/**
 * Created by denh on 17/2/22.
 */

var token = '<?=$this->token?>';
var id = common.getParam('id');
var userStatus = '<?=$user_status?>';
var app = new Vue({
    el: '#container',
    data: {
        data: {},
        author : {},
        classExt : {},
        startTime : ''
    },
    methods : {
        detailUrl : function(id){
            common.redirect('meeting', 'detail', 'id='+id);
        }
    }
});

getData();

function getData() {
    common.serverUrl = '<?=BACK_INTERFACE_BASE_URL?>';
    common.net('CardController_cardDetail',token, id, function(result){
        if(result.code != 0) {
            common.showMsgBox(result.msg);
        } else {
            console.log(result.result);

            app.data = result.result;
            app.startTime = common.getDate(result.result.classExt.startTime, true, true);
            app.author = result.result.author;
            app.classExt = result.result.classExt;

            title = result.result.title;
            desc = $(result.result.content).text();
            imgUrl = result.result.author.icon;
            shareToWx(result.result.title, desc, imgUrl);
        }
    });
}

//取消报名
function cancelSignUp() {
    common.net('CardController_cancelClassSignUp', token, id, function(result){
        console.log('singUp:'+result);
    });
}

function courseDetail() {
    isSign = app.data.isSign; //是否已报名
    courseStatus = app.data.classExt.status; //课堂状态 0 未开始，1进行中 2已结束
    if (courseStatus == 0) {
       if (isSign) {
           buttonName = '取消报名';
       } else {
           buttonName = '报名上课';
       }
    } else if (courseStatus == 1) {
        buttonName = '进入课程';
    } else if (courseStatus == 2) {
        buttonName = '课程回顾';
    }

    common.net('CardController_classSignUp', token, id, function(result){
        console.log('singUp:'+result);
    });
}


function shareToWx(title, desc, imgUrl){
    wx.config({
        debug: false,
        appId: '<?php echo $this->signPackage["appId"];?>',
        timestamp: '<?php echo $this->signPackage["timestamp"];?>',
        nonceStr: '<?php echo $this->signPackage["nonceStr"];?>',
        signature: '<?php echo $this->signPackage["signature"];?>',
        jsApiList: [
            'onMenuShareAppMessage',
            'onMenuShareTimeline',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone'
        ]
    });
    desc = '【欢迎报名】'+desc;
    links = '';
    weixinShare(title, desc, links, imgUrl);
}


(function(win,doc){
    function change(){
        doc.documentElement.style.fontSize=doc.documentElement.clientWidth/375*23.4375+'px';
    }
    change();
    win.addEventListener('resize',change,false);
})(window,document);

$(".dowmloadFooter span img").click(function(){
    $(".dowmloadFooter").hide();
});